home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Virtual User / Virtual User Current Release / Examples / External Tool Templates / CPlus Tool Template / Request.cp < prev    next >
Encoding:
Text File  |  1998-06-04  |  25.1 KB  |  870 lines  |  [TEXT/MPS ]

  1. /*
  2.  *    File:        Request.cp
  3.  *
  4.  *    Contains:    xxx put contents here xxx
  5.  *
  6.  *    Written by:    Rick Violet
  7.  *
  8.  *    Copyright:    © 1992 by Apple Computer, Inc., all rights reserved.
  9.  *
  10.  *    Change History (most recent first):
  11.  *
  12.  *                11/18/92    RV        xxx put comment here xxx
  13.  *                06/19/94    SBR        Added ExtractValueFromNthParam methods
  14.  *                09/11/94    SBR        Added ExtractValueFromNthParam for Boolean
  15.  *
  16.  *    To Do:
  17.  */
  18.  
  19. #ifndef        __Request__
  20. #include        "Request.h"
  21. #endif
  22.  
  23. #ifndef        __RequestDispatcher__
  24. #include        "RequestDispatcher.h"
  25. #endif
  26.  
  27. #ifndef        __ERRORS__
  28. #include        <Errors.h>
  29. #endif
  30.  
  31. /*SBR Hacked these in 05/24/94*/
  32. /*
  33. #ifndef        __STREAM__
  34. #include        "Stream.h"
  35. #endif
  36. */
  37.  
  38. #ifndef        __STRINGS__
  39. #include        <Strings.h>
  40. #endif
  41.  
  42. #ifndef        __TEXTUTILS__
  43. #include        <TextUtils.h>
  44. #endif
  45.  
  46. //—————————————————————————————————————————————————————————————————————————————————————
  47. //                                Global Variables
  48. //—————————————————————————————————————————————————————————————————————————————————————
  49. extern    RequestDispatcher*        gTheRequestDispatcher;
  50. extern    ThreadID                gRequestDispatcherThreadID;
  51.  
  52. //—————————————————————————————————————————————————————————————————————————————————————
  53. //    Request::Request    -    constructor.
  54. //—————————————————————————————————————————————————————————————————————————————————————
  55. Request::Request()
  56. {
  57.     fWhichService         = nil;            //————    No Request name yet
  58.     fParamList             = nil;            //————    create empty list of parameters
  59.     fReturnValue         = nil;            //————    create empty return value
  60.     fErrorCode             = noErr;        //————    No errors yet
  61.     fErrorMessage         = nil;            //————    No error message yet
  62.     fCanceled             = false;        //————    Not canceled yet
  63.     fRequestIdentifier     = 0;            //————    No identifier yet
  64.  
  65.         /*SBR Hacked this in 10/16/94 */
  66.     fThreadID            = kNoThreadID;    //————    No thread has been assigned yet
  67.     fThreadOptions        = 0;            //————    No thread options have been assigned yet
  68.     fService            = nil;            //————    No service has been assigned
  69. }
  70.  
  71. //—————————————————————————————————————————————————————————————————————————————————————
  72. //    Request::~Request    -    destructor.
  73. //—————————————————————————————————————————————————————————————————————————————————————
  74. Request::~Request()
  75. {
  76.         //————    dispose of fWhichService 
  77.     if( fWhichService != nil )
  78.     {
  79.         delete fWhichService;
  80.     }
  81.  
  82.         //————    dispose of fParamList 
  83.     if( fParamList != nil )
  84.     {
  85.         delete fParamList;
  86.     }
  87.  
  88.         //————    dispose of fReturnValue 
  89.     if( fReturnValue != nil )
  90.     {
  91.         delete fReturnValue;
  92.     }
  93.  
  94.         //————    dispose of fErrorMessage 
  95.     if( fErrorMessage != nil )
  96.     {
  97.         delete fErrorMessage;
  98.     }
  99. }
  100.  
  101. //—————————————————————————————————————————————————————————————————————————————————————
  102. //    Request::Initialize    -    initialize the Request
  103. //—————————————————————————————————————————————————————————————————————————————————————
  104. OSErr
  105. Request::Initialize()
  106. {
  107.         //————    Tell V.U. not to time out for at least kDefaultTimeOutSeconds
  108.     ResetTimeOutCounter();    
  109.         
  110.     return noErr;
  111. }
  112.  
  113. //—————————————————————————————————————————————————————————————————————————————————————
  114. //    Request::HasBeenCanceled    - Check to see if this command has been canceled
  115. //—————————————————————————————————————————————————————————————————————————————————————
  116. Boolean
  117. Request::HasBeenCanceled()
  118. {
  119.     return fCanceled; 
  120. }
  121.  
  122. //—————————————————————————————————————————————————————————————————————————————————————
  123. //    Request::ResetTimeOutCounter - inform V.U. to not let this Request time out
  124. //—————————————————————————————————————————————————————————————————————————————————————
  125. void
  126. Request::ResetTimeOutCounter( unsigned long pNewTimeOutInterval )
  127. {    
  128.         //————    Set up the Time Manager task to fire again at a later time
  129.     if( !HasBeenCanceled() )
  130.     {
  131.             //————    Keep Track of when we'll time out
  132.         fSendResetTicks = TickCount() + (pNewTimeOutInterval * 60);
  133.     }
  134. }
  135.  
  136. //—————————————————————————————————————————————————————————————————————————————————————
  137. //    Request::IsACancelRequest    - Is this a Cancel Request?
  138. //                                    return true if this is a cancel service request
  139. //—————————————————————————————————————————————————————————————————————————————————————
  140. Boolean
  141. Request::IsACancelRequest()
  142. {
  143.     if( relstring( fWhichService, (char*)kVUAECancelService, false, true ) == 0 )
  144.     {
  145.         return true;
  146.     }
  147.     else
  148.     {
  149.         return false;
  150.     }
  151. }
  152.  
  153. //—————————————————————————————————————————————————————————————————————————————————————
  154. //    Request::IsCancelRequestForThisRequest    - is the cancel request
  155. //        passed in as a parameter for canceling this sevice request object
  156. //—————————————————————————————————————————————————————————————————————————————————————
  157. Boolean
  158. Request::IsCancelRequestForThisRequest( Request* pCancelReq )
  159. {
  160.     long    tReqID;
  161.     
  162.         //————    Get the Identifier of the request to cancel 
  163.         //————    from the Cancel Request object
  164.     tReqID = pCancelReq->GetIdentifierOfRequesttoCancel();
  165.     if( tReqID == fRequestIdentifier )
  166.     {
  167.         return true;
  168.     }
  169.     else
  170.     {
  171.         return false;
  172.     }
  173. }
  174.  
  175.         /*SBR Hacked this in 10/16/94 */
  176. //—————————————————————————————————————————————————————————————————————————————————————
  177. //    Request::CancelThisRequest    - cancel this request
  178. //—————————————————————————————————————————————————————————————————————————————————————
  179. void
  180. Request::CancelThisRequest( )
  181. {
  182.     ThreadID        tReqThreadID;
  183.     ThreadState        tReqThreadState;
  184.     OSErr            tErr;
  185.     
  186.     fCanceled = true;
  187.     
  188.     if( this->IsThreaded() )
  189.     {
  190.             //————    See if the request being canceled is in a stopped thread. If it is, 
  191.             //————    set its state to Ready so it gets time to recognize the cancel.
  192.         tReqThreadID = this->GetThreadID();
  193.  
  194.         tErr = GetThreadState( tReqThreadID, &tReqThreadState );
  195.         if( tErr != noErr )
  196.         {
  197.             DebugStr( "\pRequest::CancelThisRequest- error from GetThreadState" );
  198.             return;
  199.         }
  200.         
  201.         if( tReqThreadState == kStoppedThreadState )
  202.         {
  203.             tErr = SetThreadState( tReqThreadID, kReadyThreadState, kNoThreadID );
  204.             if( tErr != noErr )
  205.             {
  206.                 DebugStr( "\pRequest::CancelThisRequest- error from SetThreadState" );
  207.                 return;
  208.             }
  209.         }
  210.     }
  211. }
  212.  
  213. //—————————————————————————————————————————————————————————————————————————————————————
  214. //    Request::IsThreaded    - Is this Request executing in a different thread?
  215. //—————————————————————————————————————————————————————————————————————————————————————
  216. Boolean
  217. Request::IsThreaded()
  218. {
  219.         //————    gRequestDispatcherThreadID could be kNoThreadID if app is non-threaded
  220.         //————    commented this out to support non-threaded services executed in a 
  221.         //————    separate thread from the RequestDispatcher or Application thread
  222.     return !(( fThreadID == kNoThreadID ) || ( fThreadID == gRequestDispatcherThreadID ));
  223. }
  224.  
  225. //—————————————————————————————————————————————————————————————————————————————————————
  226. //    Request::SetErrorCode    - set the Error code for this request
  227. //—————————————————————————————————————————————————————————————————————————————————————
  228. void
  229. Request::SetErrorCode( OSErr tErr )
  230. {
  231.     fErrorCode = tErr;
  232. }
  233.  
  234. //—————————————————————————————————————————————————————————————————————————————————————
  235. //    Request::SetErrorMessage    - set the Error message for this request
  236. //—————————————————————————————————————————————————————————————————————————————————————
  237. void
  238. Request::SetErrorMessage( char* tErrText )
  239. {
  240.         //————    Keep Request status in sync with the error code
  241.     fErrorMessage = new char[ strlen( tErrText ) + 1];
  242.     if( fErrorMessage )
  243.     {
  244.         strcpy( fErrorMessage, tErrText );
  245.     }
  246. }
  247.  
  248. //—————————————————————————————————————————————————————————————————————————————————————
  249. //    Request::GetNthParam    -    get the Nth parameter
  250. //—————————————————————————————————————————————————————————————————————————————————————
  251. OSErr
  252. Request::GetNthParam( short pIndex, ScriptValuePtr& pValue, ValueKind& pVKind )
  253. {    
  254.     if( fParamList != nil )
  255.     {
  256.         return fParamList->GetNthItem( pIndex, pValue, pVKind ); 
  257.     }
  258.     else
  259.     {
  260.         pVKind = kVUAnyKind;
  261.         pValue = nil;
  262.         return errAEWrongParameters;
  263.     }
  264. }
  265.  
  266. //—————————————————————————————————————————————————————————————————————————————————————
  267. //    Request::GetParamCount    -    return the number of parameters
  268. //—————————————————————————————————————————————————————————————————————————————————————
  269. short
  270. Request::GetParamCount()
  271. {
  272.     if( fParamList != nil )
  273.     {
  274.         return fParamList->GetCount();
  275.     }
  276.     else
  277.     {
  278.         return 0;
  279.     }
  280. }
  281.  
  282. //—————————————————————————————————————————————————————————————————————————————————————
  283. //    Request::SetReturnValue    -    set the return value for this request
  284. //                                        to a Number ScriptValue
  285. //—————————————————————————————————————————————————————————————————————————————————————
  286. void
  287. Request::SetReturnValue( short pNumber )
  288. {
  289.     ScriptValue*    tVal;
  290.     
  291.     tVal = new VUNumber( pNumber );
  292.     fReturnValue = tVal; 
  293. }
  294.  
  295. //—————————————————————————————————————————————————————————————————————————————————————
  296. //    Request::SetReturnValue    -    set the return value for this request
  297. //                                        to a Number ScriptValue
  298. //—————————————————————————————————————————————————————————————————————————————————————
  299. void
  300. Request::SetReturnValue( long pLongNumber )
  301. {
  302.     ScriptValue*    tVal;
  303.     
  304.     tVal = new VULongNumber( pLongNumber );
  305.     fReturnValue = tVal; 
  306. }
  307.  
  308. //—————————————————————————————————————————————————————————————————————————————————————
  309. //    Request::SetReturnValue    -    set the return value for this request
  310. //                                        to a Boolean ScriptValue
  311. //—————————————————————————————————————————————————————————————————————————————————————
  312. void
  313. Request::SetReturnValue( Boolean pFlag )
  314. {
  315.     ScriptValue*    tVal;
  316.     
  317.     tVal = new VUBoolean( pFlag );
  318.     fReturnValue = tVal; 
  319. }
  320.  
  321. //—————————————————————————————————————————————————————————————————————————————————————
  322. //    Request::SetReturnValue    -    set the return value for this request
  323. //                                        to a String ScriptValue
  324. //—————————————————————————————————————————————————————————————————————————————————————
  325. void
  326. Request::SetReturnValue( char* pString )
  327. {
  328.     ScriptValue*    tVal;
  329.     
  330.     tVal = new VUString( pString );
  331.     fReturnValue = tVal; 
  332. }
  333.  
  334. //—————————————————————————————————————————————————————————————————————————————————————
  335. //    Request::SetReturnValue    -    set the return value for this request
  336. //                                        to a List ScriptValue
  337. //—————————————————————————————————————————————————————————————————————————————————————
  338. void
  339. Request::SetReturnValue( ScriptValuePtr pScriptValue )
  340. //    fReturnValue = pScriptValue; 
  341.     fReturnValue = pScriptValue->Clone();
  342. }
  343.  
  344. //—————————————————————————————————————————————————————————————————————————————————————
  345. //    Request::SetReturnValue    -    set the return value for this request
  346. //                                        to a String ScriptValue
  347. //—————————————————————————————————————————————————————————————————————————————————————
  348. void
  349. Request::SetWhichService( char* pServiceText )
  350. {
  351.     fWhichService = new char[ strlen( pServiceText ) + 1 ];
  352.     if( fWhichService == nil )
  353.     {
  354.         SetErrorCode( memFullErr );
  355.         SetErrorMessage( "Failed to allocate string for Request object." );
  356.     }
  357.     else
  358.     {
  359.         strcpy( fWhichService, pServiceText );
  360.     }
  361. }
  362.  
  363. //#######################################################################
  364. //#######################################################################
  365. // The following overloaded request methods were added by Stuart Russell. 
  366. // Search for 'ExtractValueFromNthParam' to find changes to services.
  367. //#######################################################################
  368. //#######################################################################
  369.  
  370. //—————————————————————————————————————————————————————————————————————————————————————
  371. //    Request::ExtractValueFromNthParam    -    Assign a short from integer/string parameters 
  372. //                VU 2.0.1 sends numbers to tools as shorts; VU 2.1 sends them as longs.
  373. //                This method stores integers or strings into a short variable.
  374. //—————————————————————————————————————————————————————————————————————————————————————
  375. OSErr
  376. Request::ExtractValueFromNthParam( short pIndex, short* pShortPtr )
  377. {
  378.     OSErr            tErr;
  379.     ScriptValue*    tParam;
  380.     ValueKind        tKind;
  381.     
  382.         //————    Specify any kind of VUValue at first
  383.         //————    GetNthParam sets tKind to the actual kind of tParam returned
  384.     tKind = kVUAnyKind;                    
  385.     tErr = this->GetNthParam( pIndex, tParam, tKind );
  386.     
  387.     if ( tErr != noErr ) {
  388.         this->SetErrorCode( paramErr );
  389. //        this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
  390.         this->SetErrorMessage( "Failed to extract a parameter" );
  391.         return tErr;
  392.     }
  393.     
  394.     switch (tKind)
  395.     {
  396.             //————    try a long first (VU 2.1)
  397.         case kVULongNumberKind:
  398.         {
  399.             *pShortPtr = (short)((VULongNumber*)tParam)->GetNumber();
  400.         }
  401.         break;
  402.         
  403.             //————    try a short next (VU 2.0.1)
  404.         case kVUNumberKind:
  405.         {
  406.             *pShortPtr = ((VUNumber*)tParam)->GetNumber();
  407.         }
  408.         break;
  409.         
  410.             //————    try a string as a last resort
  411.         case kVUStringKind:
  412.         {
  413.             long    tempLong;
  414.             
  415.             stringtonum( ((VUString*)tParam)->GetText(), &tempLong );
  416.             *pShortPtr = (short)tempLong;
  417.         }
  418.         break;
  419.  
  420.  
  421.         default:
  422.         {
  423.             this->SetErrorCode( paramErr );
  424. //            this->SetErrorMessage( form("Error: parameter %d must be an integer or string.",pIndex) );
  425.             this->SetErrorMessage( "Error: parameter must be an integer or string." );
  426.             return paramErr;
  427.         }
  428.     }
  429.     
  430.     return noErr;
  431. }
  432.  
  433.  
  434. //—————————————————————————————————————————————————————————————————————————————————————
  435. //    Request::ExtractValueFromNthParam    -    Assign a long from integer/string parameters 
  436. //                VU 2.0.1 sends numbers to tools as shorts; VU 2.1 sends them as longs.
  437. //                This method stores integers or strings into a long variable.
  438. //—————————————————————————————————————————————————————————————————————————————————————
  439. OSErr
  440. Request::ExtractValueFromNthParam( short pIndex, long* pLongPtr )
  441. {
  442.     OSErr            tErr;
  443.     ScriptValue*    tParam;
  444.     ValueKind        tKind;
  445.     
  446.         //————    Specify any kind of VUValue at first
  447.         //————    GetNthParam sets tKind to the actual kind of tParam returned
  448.     tKind = kVUAnyKind;                    
  449.     tErr = this->GetNthParam( pIndex, tParam, tKind );
  450.     
  451.     if ( tErr != noErr ) {
  452.         this->SetErrorCode( paramErr );
  453. //        this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
  454.         this->SetErrorMessage( "Failed to extract a parameter" );
  455.         return tErr;
  456.     }
  457.     
  458.     switch (tKind)
  459.     {
  460.             //————    try a long first (VU 2.1)
  461.         case kVULongNumberKind:
  462.         {
  463.             *pLongPtr = ((VULongNumber*)tParam)->GetNumber();
  464.         }
  465.         break;
  466.         
  467.             //————    try a short next (VU 2.0.1)
  468.         case kVUNumberKind:
  469.         {
  470.             *pLongPtr = (long)((VUNumber*)tParam)->GetNumber();
  471.         }
  472.         break;
  473.         
  474.             //————    try a string as a last resort
  475.         case kVUStringKind:
  476.         {
  477.             long    tempLong;
  478.             
  479.             stringtonum( ((VUString*)tParam)->GetText(), &tempLong );
  480.             *pLongPtr = tempLong;
  481.         }
  482.         break;
  483.  
  484.  
  485.         default:
  486.         {
  487.             this->SetErrorCode( paramErr );
  488. //            this->SetErrorMessage( form("Error: parameter %d must be an integer or string.",pIndex) );
  489.             this->SetErrorMessage( "Error: parameter must be an integer or string." );
  490.             return paramErr;
  491.         }
  492.     }
  493.     
  494.     return noErr;
  495. }
  496.  
  497.  
  498. //—————————————————————————————————————————————————————————————————————————————————————
  499. //    Request::ExtractValueFromNthParam    -    Assign a char[] from a string parameter 
  500. //                This method copies a C string to the place pointed to by a char*.
  501. //—————————————————————————————————————————————————————————————————————————————————————
  502. OSErr
  503. Request::ExtractValueFromNthParam( short pIndex, char *pCharPtr )
  504. {
  505.     OSErr            tErr;
  506.     ScriptValue*    tParam;
  507.     ValueKind        tKind;
  508.     
  509.         //————    Specify any kind of VUValue at first
  510.         //————    GetNthParam sets tKind to the actual kind of tParam returned
  511.     tKind = kVUAnyKind;                    
  512.     tErr = this->GetNthParam( pIndex, tParam, tKind );
  513.     
  514.     if ( tErr != noErr ) {
  515.         this->SetErrorCode( tErr );
  516. //        this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
  517.         this->SetErrorMessage( "Failed to extract a parameter" );
  518.         return tErr;
  519.     }
  520.     
  521.     switch (tKind)
  522.     {
  523.             //————    try a string
  524.         case kVUStringKind:
  525.         {
  526.             strcpy( pCharPtr, ((VUString*)tParam)->GetText() );
  527.         }
  528.         break;
  529.         
  530.         default:
  531.         {
  532.             this->SetErrorCode( paramErr );
  533. //            this->SetErrorMessage( form("Error: parameter %d must be a string.",pIndex) );
  534.             this->SetErrorMessage( "Error: parameter must be a string." );
  535.             return paramErr;
  536.         }
  537.     }
  538.     
  539.     return noErr;
  540. }
  541.  
  542.  
  543. //—————————————————————————————————————————————————————————————————————————————————————
  544. //    Request::ExtractValueFromNthParam    -    Assign a CStr255 from a string parameter 
  545. //                This method copies a C string into a CStr255. Conversion is automatic.
  546. //                Note: a CStr255 is physically a Pascal string - see PascalString.cp.
  547. //—————————————————————————————————————————————————————————————————————————————————————
  548. OSErr
  549. Request::ExtractValueFromNthParam( short pIndex, CStr255* pCStr255Ptr )
  550. {
  551.     OSErr            tErr;
  552.     ScriptValue*    tParam;
  553.     ValueKind        tKind;
  554.     
  555.         //————    Specify any kind of VUValue at first
  556.         //————    GetNthParam sets tKind to the actual kind of tParam returned
  557.     tKind = kVUAnyKind;                    
  558.     tErr = this->GetNthParam( pIndex, tParam, tKind );
  559.     
  560.     if ( tErr != noErr ) {
  561.         this->SetErrorCode( tErr );
  562. //        this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
  563.         this->SetErrorMessage( "Failed to extract a parameter" );
  564.         return tErr;
  565.     }
  566.     
  567.     switch (tKind)
  568.     {
  569.             //————    try a string
  570.         case kVUStringKind:
  571.         {
  572.             /* overloaded operator = converts it to a Pascal string */
  573.             *pCStr255Ptr = ((VUString*)tParam)->GetText();
  574.         }
  575.         break;
  576.         
  577.         default:
  578.         {
  579.             this->SetErrorCode( paramErr );
  580. //            this->SetErrorMessage( form("Error: parameter %d must be a string.",pIndex) );
  581.             this->SetErrorMessage( "Error: parameter must be a string." );
  582.             return paramErr;
  583.         }
  584.     }
  585.     
  586.     return noErr;
  587. }
  588.  
  589.  
  590. //—————————————————————————————————————————————————————————————————————————————————————
  591. //    Request::ExtractValueFromNthParam    -    Assign a CStr63 from a string parameter 
  592. //                This method copies a C string into a CStr63. Conversion is automatic.
  593. //                Note: a CStr63 is physically a Pascal string - see PascalString.cp.
  594. //—————————————————————————————————————————————————————————————————————————————————————
  595. OSErr
  596. Request::ExtractValueFromNthParam( short pIndex, CStr63* pCStr63Ptr )
  597. {
  598.     OSErr            tErr;
  599.     ScriptValue*    tParam;
  600.     ValueKind        tKind;
  601.     
  602.         //————    Specify any kind of VUValue at first
  603.         //————    GetNthParam sets tKind to the actual kind of tParam returned
  604.     tKind = kVUAnyKind;                    
  605.     tErr = this->GetNthParam( pIndex, tParam, tKind );
  606.     
  607.     if ( tErr != noErr ) {
  608.         this->SetErrorCode( tErr );
  609. //        this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
  610.         this->SetErrorMessage( "Failed to extract a parameter" );
  611.         return tErr;
  612.     }
  613.     
  614.     switch (tKind)
  615.     {
  616.             //————    try a string
  617.         case kVUStringKind:
  618.         {
  619.             /* overloaded operator = converts it to a Pascal string */
  620.             *pCStr63Ptr = ((VUString*)tParam)->GetText();
  621.         }
  622.         break;
  623.         
  624.         default:
  625.         {
  626.             this->SetErrorCode( paramErr );
  627. //            this->SetErrorMessage( form("Error: parameter %d must be a string.",pIndex) );
  628.             this->SetErrorMessage( "Error: parameter must be a string." );
  629.             return paramErr;
  630.         }
  631.     }
  632.     
  633.     return noErr;
  634. }
  635.  
  636.  
  637. //—————————————————————————————————————————————————————————————————————————————————————
  638. //    Request::ExtractValueFromNthParam    -    Assign a CStr32 from a string parameter 
  639. //                This method copies a C string into a CStr32. Conversion is automatic.
  640. //                Note: a CStr32 is physically a Pascal string - see PascalString.cp.
  641. //—————————————————————————————————————————————————————————————————————————————————————
  642. OSErr
  643. Request::ExtractValueFromNthParam( short pIndex, CStr32* pCStr32Ptr )
  644. {
  645.     OSErr            tErr;
  646.     ScriptValue*    tParam;
  647.     ValueKind        tKind;
  648.     
  649.         //————    Specify any kind of VUValue at first
  650.         //————    GetNthParam sets tKind to the actual kind of tParam returned
  651.     tKind = kVUAnyKind;                    
  652.     tErr = this->GetNthParam( pIndex, tParam, tKind );
  653.     
  654.     if ( tErr != noErr ) {
  655.         this->SetErrorCode( tErr );
  656. //        this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
  657.         this->SetErrorMessage( "Failed to extract a parameter" );
  658.         return tErr;
  659.     }
  660.     
  661.     switch (tKind)
  662.     {
  663.             //————    try a string
  664.         case kVUStringKind:
  665.         {
  666.             /* overloaded operator = converts it to a Pascal string */
  667.             *pCStr32Ptr = ((VUString*)tParam)->GetText();
  668.         }
  669.         break;
  670.         
  671.         default:
  672.         {
  673.             this->SetErrorCode( paramErr );
  674. //            this->SetErrorMessage( form("Error: parameter %d must be a string.",pIndex) );
  675.             this->SetErrorMessage( "Error: parameter must be a string." );
  676.             return paramErr;
  677.         }
  678.     }
  679.     
  680.     return noErr;
  681. }
  682.  
  683.  
  684. //—————————————————————————————————————————————————————————————————————————————————————
  685. //    Request::ExtractValueFromNthParam    -    Assign a CStr31 from a string parameter 
  686. //                This method copies a C string into a CStr31. Conversion is automatic.
  687. //                Note: a CStr31 is physically a Pascal string - see PascalString.cp.
  688. //—————————————————————————————————————————————————————————————————————————————————————
  689. OSErr
  690. Request::ExtractValueFromNthParam( short pIndex, CStr31* pCStr31Ptr )
  691. {
  692.     OSErr            tErr;
  693.     ScriptValue*    tParam;
  694.     ValueKind        tKind;
  695.     
  696.         //————    Specify any kind of VUValue at first
  697.         //————    GetNthParam sets tKind to the actual kind of tParam returned
  698.     tKind = kVUAnyKind;                    
  699.     tErr = this->GetNthParam( pIndex, tParam, tKind );
  700.     
  701.     if ( tErr != noErr ) {
  702.         this->SetErrorCode( tErr );
  703. //        this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
  704.         this->SetErrorMessage( "Failed to extract a parameter" );
  705.         return tErr;
  706.     }
  707.     
  708.     switch (tKind)
  709.     {
  710.             //————    try a string
  711.         case kVUStringKind:
  712.         {
  713.             /* overloaded operator = converts it to a Pascal string */
  714.             *pCStr31Ptr = ((VUString*)tParam)->GetText();
  715.         }
  716.         break;
  717.         
  718.         default:
  719.         {
  720.             this->SetErrorCode( paramErr );
  721. //            this->SetErrorMessage( form("Error: parameter %d must be a string.",pIndex) );
  722.             this->SetErrorMessage( "Error: parameter must be a string." );
  723.             return paramErr;
  724.         }
  725.     }
  726.     
  727.     return noErr;
  728. }
  729.  
  730. //—————————————————————————————————————————————————————————————————————————————————————
  731. //    Request::ExtractValueFromNthParam    -    Assign a ScriptValue* from a string parameter.
  732. //                This method stores a ScriptValue* into a ScriptValue* variable. No 
  733. //                copying occurs. The pScriptValuePtrPtr will point to a member of an item
  734. //                in a VUList in the request object. This VUList will be deleted as soon as 
  735. //                your service's ProcessRequest() method returns, so you should extract the
  736. //                contents ASAP if you want to keep them.
  737. //—————————————————————————————————————————————————————————————————————————————————————
  738. OSErr
  739. Request::ExtractValueFromNthParam( short pIndex, ScriptValue** pScriptValuePtrPtr )
  740. {
  741.     OSErr            tErr;
  742.     ScriptValue*    tParam;
  743.     ValueKind        tKind;
  744.     
  745.         //————    Specify any kind of VUValue at first
  746.         //————    GetNthParam sets tKind to the actual kind of tParam returned
  747.     tKind = kVUAnyKind;                    
  748.     tErr = this->GetNthParam( pIndex, tParam, tKind );
  749.     
  750.     if ( tErr != noErr ) {
  751.         this->SetErrorCode( tErr );
  752. //        this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
  753.         this->SetErrorMessage( "Failed to extract a parameter" );
  754.         return tErr;
  755.     }
  756.     
  757.     switch (tKind)
  758.     {
  759.             //————    try any kind
  760.         case kVUListKind:
  761.         {
  762.             *pScriptValuePtrPtr = ((ScriptValue*)tParam);
  763.             //*pScriptValuePtrPtr = (ScriptValue*)(tParam->Clone());
  764.         }
  765.         break;
  766.         
  767.         default:
  768.         {
  769.             this->SetErrorCode( paramErr );
  770. //            this->SetErrorMessage( form("Error: parameter %d must be a ScriptValue.",pIndex) );
  771.             this->SetErrorMessage( "Error: parameter must be a ScriptValue." );
  772.             return paramErr;
  773.         }
  774.     }
  775.     
  776.     return noErr;
  777. }
  778.  
  779.  
  780. //—————————————————————————————————————————————————————————————————————————————————————
  781. //    Request::ExtractValueFromNthParam    -    Assign a char* from a string parameter 
  782. //                This method stores a char* into a char* variable. No copying occurs.
  783. //                The pCharPtr will point to a member of an item in a VUList, which may 
  784. //                be deleted at any time, so you should extract the contents ASAP.
  785. //—————————————————————————————————————————————————————————————————————————————————————
  786. OSErr
  787. Request::ExtractValueFromNthParam( short pIndex, char** pCharPtrPtr )
  788. {
  789.     OSErr            tErr;
  790.     ScriptValue*    tParam;
  791.     ValueKind        tKind;
  792.     
  793.         //————    Specify any kind of VUValue at first
  794.         //————    GetNthParam sets tKind to the actual kind of tParam returned
  795.     tKind = kVUAnyKind;                    
  796.     tErr = this->GetNthParam( pIndex, tParam, tKind );
  797.     
  798.     if ( tErr != noErr ) {
  799.         this->SetErrorCode( tErr );
  800. //        this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
  801.         this->SetErrorMessage( "Failed to extract a parameter" );
  802.         return tErr;
  803.     }
  804.     
  805.     switch (tKind)
  806.     {
  807.             //————    try a string
  808.         case kVUStringKind:
  809.         {
  810.             *pCharPtrPtr = ((VUString*)tParam)->GetText();
  811.         }
  812.         break;
  813.         
  814.         default:
  815.         {
  816.             this->SetErrorCode( paramErr );
  817. //            this->SetErrorMessage( form("Error: parameter %d must be a string.",pIndex) );
  818.             this->SetErrorMessage( "Error: parameter must be a string." );
  819.             return paramErr;
  820.         }
  821.     }
  822.     
  823.     return noErr;
  824. }
  825.  
  826. //—————————————————————————————————————————————————————————————————————————————————————
  827. //    Request::ExtractValueFromNthParam    -    Assign a Boolean from a Boolean parameter 
  828. //                This method stores a Boolean into a Boolean variable.
  829. //—————————————————————————————————————————————————————————————————————————————————————
  830. OSErr
  831. Request::ExtractValueFromNthParam( short pIndex, Boolean* pBooleanPtr )
  832. {
  833.     OSErr            tErr;
  834.     ScriptValue*    tParam;
  835.     ValueKind        tKind;
  836.     
  837.         //————    Specify any kind of VUValue at first
  838.         //————    GetNthParam sets tKind to the actual kind of tParam returned
  839.     tKind = kVUAnyKind;                    
  840.     tErr = this->GetNthParam( pIndex, tParam, tKind );
  841.     
  842.     if ( tErr != noErr ) {
  843.         this->SetErrorCode( tErr );
  844. //        this->SetErrorMessage( form("Failed to extract parameter %d", pIndex) );
  845.         this->SetErrorMessage( "Failed to extract a parameter" );
  846.         return tErr;
  847.     }
  848.     
  849.     switch (tKind)
  850.     {
  851.             //————    we want a Boolean
  852.         case kVUBooleanKind:
  853.         {
  854.             *pBooleanPtr = ((VUBoolean*)tParam)->GetBoolean();
  855.         }
  856.         break;
  857.         
  858.         default:
  859.         {
  860.             this->SetErrorCode( paramErr );
  861. //            this->SetErrorMessage( form("Error: parameter %d must be a Boolean.",pIndex) );
  862.             this->SetErrorMessage( "Error: parameter must be a Boolean." );
  863.             return paramErr;
  864.         }
  865.     }
  866.     
  867.     return noErr;
  868. }
  869.